#ifndef WindowSystem_First
#define WindowSystem_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Port.h"

enum WindowType {
	eWinPlain,
	eWinStandard,
	eWinDialog,
	eWinPulldownMenu,
	eWinPopupMenu,
	eWinIcon
};

enum WindowFlags {
	eWinDefault     =   0,
	eWinBlock       =   1,
	eWinFixed       =   2,
	eWinCanClose    =   4
};

class VObject;
class Window;
class WindowPort;
class Data;
class WindowColorMap;
class IAC;
class EvtHandler;
class IACImpl;

//---- WindowSystem ------------------------------------------------------------

class WindowSystem : public Object {
public:
	static bool batch;
	static u_long lasttime;
	static bool fullscreen;
	static WindowPort *grabport;
	static Token lastClick;
	static int Clicks;
	static Rectangle screenRect;
	static OrdCollection *allwins;
	static WindowColorMap *wcmap;

	static void WSInit();
	static WindowSystem *Load(const char *name, const char *classname);

public:
	MetaDef(WindowSystem);
	WindowSystem();
	~WindowSystem();

	void Update();

	WindowPort *FindWindowWithId(int winid);

	virtual bool Init0();   // returns TRUE on OK
	virtual void Init();
	virtual WindowPort *MakeWindow(Window *bw, WindowType wt, GrCursor curs);
	virtual void RemoveWindow(WindowPort*);
	void AddWindow(WindowPort*);
	virtual FontManager *MakeFontManager();
	virtual DevBitmap *MakeDevBitmap(Point sz, u_short *data, u_short depth,
					bool freedata= FALSE, u_short pad= 2);
	virtual void graphicDelay(unsigned int);

	virtual void DevBell(long duration);
	virtual int DevHaveSelection(Data *data);
	virtual VObject *MakeWindowBorder(WindowType wt, VObject *in,
					char *title, bool block, bool fixed);
	virtual IACImpl *MakeRpcImpl(IAC *sc);

	void SetWait();
	void ResetWait();
	virtual void DevCheckSelection();

	int DragDrop(int code, const Point &lp);

	virtual int DevFindWindow(const Point &p);
	virtual int DevDragDrop(int code, int winid, const Point &lp,
								Rectangle *r= 0);
	virtual bool DevIsEtWindow(int winid);
};

extern WindowSystem *gWindowSystem;
extern bool         gColor;
extern int          gDepth;
extern int          gMaxDepth;
extern bool         gGreyScale;

inline void GraphicDelay(unsigned int duration)
	{ gWindowSystem->graphicDelay(duration); }

#endif
